package com.zjl.hiring.common.util;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zjl.hiring.talent.entity.TalentEntity;

/**
 * 这是系统的工具类
 * 
 * @author Administrator
 *
 */
public class AppUtil {

	private AppUtil() {

	}
	/**
	 * 判断是否已经登录
	 * @param request
	 * @return
	 */
	public static boolean isLogin(HttpServletRequest request) {
		Object obj = request.getSession().getAttribute("talent");
		return obj == null ? false : true;
	}
	/**
	 * 获取session里的talentId
	 * @param request
	 * @param response
	 * @return
	 */
	public static int getTalentId(HttpServletRequest request,
			HttpServletResponse response) {
		Object obj = request.getSession().getAttribute("talent");
		if (obj == null) {
			try {
				try {
					request.getRequestDispatcher(
							"view/talent/login.jsp?sessionInvalidate=true")
							.forward(request, response);
				} catch (ServletException e) {
					e.printStackTrace();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			throw new RuntimeException("回话已关闭！");
		} else {
			TalentEntity talent = (TalentEntity) obj;
			return talent.getId();
		}
	}
}
